package com.guigu.controller.lq.controller;

import com.guigu.controller.lq.pojo.*;
import com.guigu.controller.lq.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class LqModelController {
    @Autowired
    LqModelService lqModelService;
    Integer id;
    @Autowired
    LqFoodService lqFoodService;
    @Autowired
    LqMotionService lqMotionService;
    @Autowired
    LqYdfaService lqYdfaService;
    @Autowired
    LqYsfaService lqYsfaService;
    @RequestMapping("/mod")
    public PageVO<LqModel>findmod(@RequestBody PageVO pageVO){
        PageVO<LqModel> lqModelPageVO = lqModelService.find(pageVO.getPage(), pageVO.getNum(), pageVO.getModeltitle());
        return lqModelPageVO;
    }
    @RequestMapping("/ysc")
        public List<LqFood> findys(){
        List<LqFood> findys = lqFoodService.findys();
        return findys;
    }
    @RequestMapping("/ydc")
    public  List<LqMotion> findyd(){
        List<LqMotion> findyd = lqMotionService.findyd();

        return findyd;
    }
    @RequestMapping("/tjmb")
    public int tjmb(@RequestBody LqModel lqModel){
        int tjmb = lqModelService.tjmb(lqModel);
        id=lqModel.getId();
        return tjmb;
    }
    @RequestMapping("/tjys")
    public  int tjys(@RequestBody LqFood [] aa ){
        LqYsfa lqYsfa = new LqYsfa();
        for (int i=0;i< aa.length;i++){
            lqYsfa.setModid(id);
            lqYsfa.setBm(aa[i].getBm());
            lqYsfa.setSpmc(aa[i].getSpmc());
            lqYsfa.setType(aa[i].getType());
            lqYsfa.setFoodenergy(aa[i].getFoodenergy());
            lqYsfa.setFoodprotein(aa[i].getFoodprotein());
            lqYsfa.setFoodfat(aa[i].getFoodfat());
            lqYsfa.setExpl(aa[i].getExpl());
            lqYsfaService.tjys(lqYsfa);
        }
        return 1;
    }
    @RequestMapping("/tjyd")
    public int tjyd(@RequestBody LqMotion [] aa){
        LqYdfa lqYdfa = new LqYdfa();
        for (int i=0;i< aa.length;i++){
            lqYdfa.setModid(id);
            lqYdfa.setMotion(aa[i].getMotion());
            lqYdfa.setMotionmc(aa[i].getMotionmc());
            lqYdfa.setMotionintensity(aa[i].getMotionintensity());
            lqYdfa.setMotiontime(aa[i].getMotiontime());
            lqYdfa.setMaxage(aa[i].getMaxage());
            lqYdfa.setMeasure(aa[i].getMeasure());
            lqYdfa.setMinage(aa[i].getMinage());
            lqYdfa.setGender(aa[i].getGender());
            lqYdfa.setStretchpart(aa[i].getStretchpart());
            lqYdfaService.tjyd(lqYdfa);
            System.out.println(aa[i].getMotionmc());
        }
        return 1;
    }
    @RequestMapping("/selmb")
    public LqModel selmb(@RequestBody LqModel lqModel){
        LqModel selmb = lqModelService.selmb(lqModel.getId());
        return selmb;
    }
    @RequestMapping("/selys")
    public List<LqYsfa> setys(@RequestBody LqYsfa lqYsfa){
        List<LqYsfa> selys = lqYsfaService.selys(lqYsfa.getModid());
        return  selys;
    }
    @RequestMapping("/selyd")
    public List<LqYdfa> setyd(@RequestBody LqYdfa lqYdfa){
        List<LqYdfa> setyd = lqYdfaService.setyd(lqYdfa.getModid());
        return setyd;
    }
    @RequestMapping("/upzt")
    public int upzt(@RequestBody LqModel lqModel){
        int upzt = lqModelService.upzt(lqModel);
        return upzt;
    }
    @RequestMapping("/delmb")
    public  int delmb(@RequestBody LqModel lqModel){
        int delmb = lqModelService.delmb(lqModel.getId());
        return delmb;
    }
    @RequestMapping("/delys")
    public  int delys(@RequestBody LqYsfa lqYsfa){
        int delys = lqYsfaService.delys(lqYsfa.getModid());
        return delys;
    }
    @RequestMapping("/delyd")
    public int delyd(@RequestBody LqYdfa lqYdfa){
        int delyd = lqYdfaService.delyd(lqYdfa.getModid());
        return delyd;
    }
    @RequestMapping("/upmb")
    public int upmb(@RequestBody LqModel lqModel){
        int upmb = lqModelService.upmb(lqModel);
        id=lqModel.getId();
        lqYdfaService.delyd(id);
        System.out.println("1111111111");
        lqYsfaService.delys(id);
        return upmb;
    }
    @RequestMapping("/upys")
    public  int upys(@RequestBody LqFood [] aa ){
        LqYsfa lqYsfa = new LqYsfa();
        for (int i=0;i< aa.length;i++){
            lqYsfa.setModid(id);
            lqYsfa.setBm(aa[i].getBm());
            lqYsfa.setSpmc(aa[i].getSpmc());
            lqYsfa.setType(aa[i].getType());
            lqYsfa.setFoodenergy(aa[i].getFoodenergy());
            lqYsfa.setFoodprotein(aa[i].getFoodprotein());
            lqYsfa.setFoodfat(aa[i].getFoodfat());
            lqYsfa.setExpl(aa[i].getExpl());
            lqYsfaService.tjys(lqYsfa);
        }
        return 1;
    }
    @RequestMapping("/upyd")
    public int upyd(@RequestBody LqMotion [] aa){
        LqYdfa lqYdfa = new LqYdfa();
        for (int i=0;i< aa.length;i++){
            lqYdfa.setModid(id);
            lqYdfa.setMotion(aa[i].getMotion());
            lqYdfa.setMotionmc(aa[i].getMotionmc());
            lqYdfa.setMotionintensity(aa[i].getMotionintensity());
            lqYdfa.setMotiontime(aa[i].getMotiontime());
            lqYdfa.setMaxage(aa[i].getMaxage());
            lqYdfa.setMeasure(aa[i].getMeasure());
            lqYdfa.setMinage(aa[i].getMinage());
            lqYdfa.setGender(aa[i].getGender());
            lqYdfa.setStretchpart(aa[i].getStretchpart());
            lqYdfaService.tjyd(lqYdfa);
            System.out.println(aa[i].getMotionmc());
        }
        return 1;
    }
}
